package chatClient;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

import javax.imageio.ImageIO;

import mappingBD.*;

public class Emission implements Runnable {

	private OutputStream out;
	private Client client = null;
	private SalleDeDiscussion sd = null;
	private Message message = null;
	private Synchronisation sync = null;
	private boolean donneeAEmettre = false;
	private ObjectOutputStream objectPourServeur = null;
	private Socket socket = null;

	public Emission(OutputStream out) {
		this.out = out;
	}

	public Emission() throws IOException {
		socket = ClientMain.getSocket();
		this.out = socket.getOutputStream();

	}

	public void run() {
		try {
			objectPourServeur = new ObjectOutputStream(out);
		} catch (IOException e) {
			e.printStackTrace();
		}

		try {
			System.out.println("Essaie d'envoyer une requete...........");
			if (client != null) {
				System.out.println("Envoie....Client");
				objectPourServeur.writeObject(client);
			} else if (message != null) {
				System.out.println("Envoie....Message");
				objectPourServeur.writeObject(message);
			} else if (sd != null) {
				System.out.println("Envoie....SD");
				objectPourServeur.writeObject(sd);
			} else if (sync != null) {
				System.out.println("Envoie....SYNC");
				objectPourServeur.writeObject(sync);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// GETTERS AND SETTERS

	public OutputStream getOut() {
		return out;
	}

	public void setOut(OutputStream out) {
		this.out = out;
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public SalleDeDiscussion getSd() {
		return sd;
	}

	public void setSd(SalleDeDiscussion sd) {
		this.sd = sd;
	}

	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	public Synchronisation getSync() {
		return sync;
	}

	public void setSync(Synchronisation sync) {
		this.sync = sync;
	}

	public boolean isDonneeAEmettre() {
		return donneeAEmettre;
	}

	public void setDonneeAEmettre(boolean donneeAEmettre) {
		this.donneeAEmettre = donneeAEmettre;
	}

	public ObjectOutputStream getObjectPourServeur() {
		return objectPourServeur;
	}

	public void setObjectPourServeur(ObjectOutputStream objectPourServeur) {
		this.objectPourServeur = objectPourServeur;
	}

	public Socket getSocket() {
		return socket;
	}

	public void setSocket(Socket socket) {
		this.socket = socket;
	}

}
